GPPPARAMS = -m32 -Ofast -std=c++20 -fno-use-cxa-atexit -nostdlib -nostartfiles -fno-exceptions -fno-rtti -fno-leading-underscore
ASPARAMS = --32
LDPARAMS = -melf_i386 -s

objects = loader.o kernel.o

kernel.o: kernel.cc
	g++ $(GPPPARAMS) -c kernel.cc

%.o: %.s
	as $(ASPARAMS) -o $@ $<

mykernel.bin: linker.ld $(objects)
	ld $(LDPARAMS) -T $< -o $@ $(objects)

install: mykernel.bin
	sudo cp $< /boot/mykernel.bin


mykernel.iso: mykernel.bin
	mkdir iso
	mkdir iso/boot
	mkdir iso/boot/grub
	cp $< iso/boot/
	echo 'set timeout=0' > iso/boot/grub/grub.cfg
	echo 'set default=0' >> iso/boot/grub/grub.cfg
	echo '' >> iso/boot/grub/grub.cfg
	echo 'menuentry "My Operating System"' >> iso/boot/grub/grub.cfg
	echo ' multiboot /boot/mykernel.bin' >> iso/boot/grub/grub.cfg
	echo ' boot' >> iso/boot/grub/grub.cfg
	echo '}' >> iso/boot/grub/grub.cfg
	grub-mkrescue --output=$@ iso
	rm -rf iso

run: mykernel.bin
	qemu-system-i386 -kernel mykernel.bin
	

clean:
	rm *.o
	rm mykernel.bin

